Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 28, 2026

INSERT and UPDATE statements rejected schema-qualified table references (schema.table) despite this being valid SQLite syntax.

// Previously failed to parse
INSERT INTO main.tableau VALUES (1, 2), (3, 4);
UPDATE main.tableau SET n2=n1;

Changes

  • INSERT: Extended InsertStatement AST with Schema and Dot fields; parser now recognizes schema.table pattern before column list
  • UPDATE: Enabled schema qualification by passing schemaOK=true to parseQualifiedTableName (AST already supported via *QualifiedTableName)
  • Tests: Added coverage for both statement types with schema-qualified tables

The approach aligns with how CREATE TABLE handles schema qualification (separate Schema/Name fields) while UPDATE uses the existing QualifiedTableName structure.

Original prompt

This section details on the original issue you should resolve

<issue_title>Parse failure of schema.table with INSERT/UPDATE</issue_title>
<issue_description>Similarly to #31, the INSERT/UPDATE query parsing errors when targeting schemaname.tablename references.

For example, the following executes successfully in SQLite3:

sqlite> CREATE TABLE main.tableau (n1, n2);
sqlite> INSERT INTO main.tableau VALUES (1, 2), (3, 4);
sqlite> UPDATE main.tableau SET n2=n1;
sqlite> DELETE FROM main.tableau WHERE n2 > 1;
sqlite> SELECT * FROM main.tableau;
+----+----+
| n1 | n2 |
+----+----+
| 1  | 1  |
+----+----+

However, the queries after the INSERT and UPDATE queries fail to parse with github.com/rqlite/sql: https://go.dev/play/p/LrTg9SXOODx

package main

import (
	"fmt"
	"strings"

	"github.com/rqlite/sql"
)

func main() {
	for _, q := range []string{
		`INSERT INTO main.tableau VALUES (1, 2), (3, 4);`,
		`UPDATE main.tableau SET n2=n1;`,
	} {
		p := sql.NewParser(strings.NewReader(q))
		s, err := p.ParseStatement()
		fmt.Printf("%q\n   err: %v\n  stmt: %#v\n", q, err, s)
	}
}

Output:

"INSERT INTO main.tableau VALUES (1, 2), (3, 4);"
   err: 1:17: expected VALUES, SELECT, or DEFAULT VALUES, found '.'
  stmt: &sql.InsertStatement{WithClause:(*sql.WithClause)(nil), Insert:sql.Pos{Offset:0, Line:1, Column:1}, Replace:sql.Pos{Offset:0, Line:0, Column:0}, InsertOr:sql.Pos{Offset:0, Line:0, Column:0}, InsertOrReplace:sql.Pos{Offset:0, Line:0, Column:0}, InsertOrRollback:sql.Pos{Offset:0, Line:0, Column:0}, InsertOrAbort:sql.Pos{Offset:0, Line:0, Column:0}, InsertOrFail:sql.Pos{Offset:0, Line:0, Column:0}, InsertOrIgnore:sql.Pos{Offset:0, Line:0, Column:0}, Into:sql.Pos{Offset:7, Line:1, Column:8}, Table:(*sql.Ident)(0xc0000b0180), As:sql.Pos{Offset:0, Line:0, Column:0}, Alias:(*sql.Ident)(nil), ColumnsLparen:sql.Pos{Offset:0, Line:0, Column:0}, Columns:[]*sql.Ident(nil), ColumnsRparen:sql.Pos{Offset:0, Line:0, Column:0}, Values:sql.Pos{Offset:0, Line:0, Column:0}, ValueLists:[]*sql.ExprList(nil), Select:(*sql.SelectStatement)(nil), Default:sql.Pos{Offset:0, Line:0, Column:0}, DefaultValues:sql.Pos{Offset:0, Line:0, Column:0}, UpsertClause:(*sql.UpsertClause)(nil), ReturningClause:(*sql.ReturningClause)(nil)}
"UPDATE main.tableau SET n2=n1;"
   err: 1:12: expected unqualified table name, found '.'
  stmt: &sql.UpdateStatement{WithClause:(*sql.WithClause)(nil), Update:sql.Pos{Offset:0, Line:1, Column:1}, UpdateOr:sql.Pos{Offset:0, Line:0, Column:0}, UpdateOrReplace:sql.Pos{Offset:0, Line:0, Column:0}, UpdateOrRollback:sql.Pos{Offset:0, Line:0, Column:0}, UpdateOrAbort:sql.Pos{Offset:0, Line:0, Column:0}, UpdateOrFail:sql.Pos{Offset:0, Line:0, Column:0}, UpdateOrIgnore:sql.Pos{Offset:0, Line:0, Column:0}, Table:(*sql.QualifiedTableName)(0xc0000f6000), Set:sql.Pos{Offset:0, Line:0, Column:0}, Assignments:[]*sql.Assignment(nil), Where:sql.Pos{Offset:0, Line:0, Column:0}, WhereExpr:sql.Expr(nil), ReturningClause:(*sql.ReturningClause)(nil)}
  • INSERT gets parsed into a sql.InsertStatement which does not appear to be schema-aware. sql.CreateTableStatment has separate Schema and Name fields to identify the table, which InsertStatement could copy as they're using the same language constructs:

    Image Image
  • UPDATE gets parsed into a sql.UpdateTableStatement which has a Table *sql.QualifiedTableName field, despite the "expected unqualified table name" error. This seems like a straightforward bug.

    Image Image

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: otoolep <536312+otoolep@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix parse failure of schema.table with INSERT/UPDATE Support schema-qualified table names in INSERT/UPDATE statements Jan 28, 2026
Copilot AI requested a review from otoolep January 28, 2026 23:52
}
ident, _ := p.parseIdent("table name")
if stmt.Table, err = p.parseQualifiedTableName(ident, false, false, false); err != nil {
if stmt.Table, err = p.parseQualifiedTableName(ident, true, false, false); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot -- why did you make this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed the first parameter (schemaOK) from false to true to allow schema-qualified table names in UPDATE statements. The parseQualifiedTableName function was rejecting the dot separator with "expected unqualified table name" error when schemaOK=false. Since UPDATE already uses *QualifiedTableName in its AST (which supports schema.table), this was just enabling that existing capability in the parser.

Copilot AI requested a review from otoolep January 29, 2026 00:47
@otoolep otoolep marked this pull request as ready for review January 29, 2026 01:28
@otoolep otoolep merged commit a110ae1 into master Jan 29, 2026
3 checks passed
@otoolep otoolep deleted the copilot/fix-schema-table-parse-errors branch January 29, 2026 01:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parse failure of schema.table with INSERT/UPDATE

2 participants